package com.evenmo.test;

import org.apache.ibatis.session.SqlSession;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.evenmo.mapper.GoodsMapper;
import com.evenmo.mapper.OrderMapper;
import com.evenmo.mapper.UserMapper;
import com.evenmo.pojo.Goods;
import com.evenmo.pojo.Order;
import com.evenmo.pojo.User;
import com.evenmo.util.MySqlSessionFactory;

public class MybatisTest1 {

	private SqlSession session;

	private GoodsMapper goodsDao;
	private OrderMapper orderDao;
	private UserMapper userDao;
	private Goods goods;
	private User user;
	private Order order;
	@Before
	public void initDatas() {
		session = getSqlSession();
		goodsDao=session.getMapper(GoodsMapper.class);
		orderDao = session.getMapper(OrderMapper.class);
		userDao = session.getMapper(UserMapper.class);
		user=new User();
		order=new Order();
		goods=new Goods();
	}

	@After
	public void afterThings() {
		session.commit();
	
		session.close();
	}

	@Test
	public void queryUserByid() {
		user.setId(1);
		User u = userDao.queryByUserId(user);
		System.out.println(u);
	}
	
	
	@Test
	public void queryUserOfOrdersByUserId() {
		user.setId(1);
		User u = userDao.queryUserOfOrdersByUserId(user);
		System.out.println(u);
	}
	
	
	@Test
	public void queryMoreForOrderByOrderId(){
		order.setId(1);
		Order o = orderDao.queryMoreForOrderByOrderId(order);
		System.out.println(o);
	}

	@Test
	public void queryByGoodId(){
		Goods g = goodsDao.queryByGoodId(1);
		System.out.println(g);
	}
	@Test
	public void queryMoreByGoodId(){
		Goods g = goodsDao.queryMoreByGoodId(1);
		System.out.println(g);
	}
	public static SqlSession getSqlSession() {
		return MySqlSessionFactory.getSqlSession();
	}

}
